import WattTool from '@wattjs/tool'
const { v4: guid } = WattTool.uuid

// 上报监听
export function pushToObserve(observeData = {}) {
    const defStime = new Date().getTime()
    const defId = guid()
    const { id = defId, type = '', data = {}, stime = defStime, hasObserve = false } = observeData

    // 排重
    if (!WattTool.Api.getSession(`guid-${id}`)) {
      WattTool.Api.setSession(`guid-${id}`, { id, data, type, stime, hasObserve })
    }
}

export function destoryObserve(value) {
  WattTool.Api.rmSession(`guid-${value.id}`)
}

export function findObserve(id) {
  return WattTool.Api.getSession(`guid-${id}`) || {}
}

export function activeObserve(value) {
  value.hasObserve = true
  WattTool.Api.setSession(`guid-${value.id}`, value)
}

export function findAllObserve() {
  return WattTool.Api.findSession(/^guid-/)
}
